package biz.obake.team.touchprotector.f;

import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.widget.ImageView;
import android.widget.TextView;
import biz.obake.team.touchprotector.R;
import biz.obake.team.touchprotector.f.l;
import biz.obake.team.touchprotector.fingerprint.FingerprintActivity;
import biz.obake.team.touchprotector.tpservice.TPService;

public final class e implements l {
    /* access modifiers changed from: private */

    /* renamed from: b  reason: collision with root package name */
    public final ViewGroup f1611b;
    /* access modifiers changed from: private */

    /* renamed from: c  reason: collision with root package name */
    public boolean f1612c;
    /* access modifiers changed from: private */

    /* renamed from: d  reason: collision with root package name */
    public int f1613d;
    /* access modifiers changed from: private */
    public final Handler e = new Handler();
    private final Runnable f;
    /* access modifiers changed from: private */
    public final Runnable g;
    /* access modifiers changed from: private */
    public final Runnable h;
    /* access modifiers changed from: private */
    public final FingerprintActivity.b i;
    private final k j;

    static final class a implements Runnable {

        /* renamed from: b  reason: collision with root package name */
        final /* synthetic */ e f1614b;

        a(e eVar) {
            this.f1614b = eVar;
        }

        public final void run() {
            this.f1614b.f1612c = false;
            AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f);
            alphaAnimation.setDuration(250);
            this.f1614b.f1611b.startAnimation(alphaAnimation);
            this.f1614b.f1611b.setVisibility(8);
        }
    }

    public static final class b implements FingerprintActivity.b {

        /* renamed from: a  reason: collision with root package name */
        final /* synthetic */ e f1615a;

        b(e eVar) {
            this.f1615a = eVar;
        }

        public void a() {
            this.f1615a.e.removeCallbacksAndMessages((Object) null);
            biz.obake.team.touchprotector.log.a.b().d("Fingerprint: On");
            View findViewById = this.f1615a.f1611b.findViewById(R.id.fingerprint_status);
            if (findViewById != null) {
                ((TextView) findViewById).setText(R.string.panel_fingerprint_start);
                this.f1615a.e.postDelayed(this.f1615a.h, 3000);
                return;
            }
            throw new d.e("null cannot be cast to non-null type android.widget.TextView");
        }

        public void b() {
            this.f1615a.e.removeCallbacksAndMessages((Object) null);
            this.f1615a.f1612c = false;
            biz.obake.team.touchprotector.log.a.b().d("Fingerprint: Off, Succeeded");
            TPService.k("UnlockForce", "Fingerprint");
        }

        public void c(int i, CharSequence charSequence) {
            d.h.b.c.c(charSequence, "helpString");
            this.f1615a.e.removeCallbacksAndMessages((Object) null);
            View findViewById = this.f1615a.f1611b.findViewById(R.id.fingerprint_icon);
            if (findViewById != null) {
                ((ImageView) findViewById).setImageResource(R.drawable.fingerprint_error);
                View findViewById2 = this.f1615a.f1611b.findViewById(R.id.fingerprint_status);
                if (findViewById2 != null) {
                    ((TextView) findViewById2).setText(charSequence);
                    this.f1615a.e.postDelayed(this.f1615a.h, 3000);
                    return;
                }
                throw new d.e("null cannot be cast to non-null type android.widget.TextView");
            }
            throw new d.e("null cannot be cast to non-null type android.widget.ImageView");
        }

        public void d(int i, CharSequence charSequence) {
            d.h.b.c.c(charSequence, "errString");
            this.f1615a.e.removeCallbacksAndMessages((Object) null);
            if (i != 5) {
                e eVar = this.f1615a;
                eVar.f1613d = eVar.f1613d + 1;
                biz.obake.team.touchprotector.log.a b2 = biz.obake.team.touchprotector.log.a.b();
                b2.d("Fingerprint: Off, " + charSequence);
                View findViewById = this.f1615a.f1611b.findViewById(R.id.fingerprint_icon);
                if (findViewById != null) {
                    ((ImageView) findViewById).setImageResource(R.drawable.fingerprint_error);
                    View findViewById2 = this.f1615a.f1611b.findViewById(R.id.fingerprint_status);
                    if (findViewById2 != null) {
                        ((TextView) findViewById2).setText(charSequence);
                        this.f1615a.e.postDelayed(this.f1615a.g, 3000);
                        return;
                    }
                    throw new d.e("null cannot be cast to non-null type android.widget.TextView");
                }
                throw new d.e("null cannot be cast to non-null type android.widget.ImageView");
            }
            biz.obake.team.touchprotector.log.a.b().d("Fingerprint: Off");
            this.f1615a.g.run();
        }

        public void e() {
            this.f1615a.e.removeCallbacksAndMessages((Object) null);
            View findViewById = this.f1615a.f1611b.findViewById(R.id.fingerprint_icon);
            if (findViewById != null) {
                ((ImageView) findViewById).setImageResource(R.drawable.fingerprint_error);
                View findViewById2 = this.f1615a.f1611b.findViewById(R.id.fingerprint_status);
                if (findViewById2 != null) {
                    ((TextView) findViewById2).setText(R.string.panel_fingerprint_failed);
                    this.f1615a.e.postDelayed(this.f1615a.h, 3000);
                    return;
                }
                throw new d.e("null cannot be cast to non-null type android.widget.TextView");
            }
            throw new d.e("null cannot be cast to non-null type android.widget.ImageView");
        }
    }

    static final class c implements Runnable {

        /* renamed from: b  reason: collision with root package name */
        public static final c f1616b = new c();

        c() {
        }

        public final void run() {
            FingerprintActivity.g();
        }
    }

    static final class d implements Runnable {

        /* renamed from: b  reason: collision with root package name */
        final /* synthetic */ e f1617b;

        d(e eVar) {
            this.f1617b = eVar;
        }

        public final void run() {
            this.f1617b.i.d(0, biz.obake.team.touchprotector.c.w(R.string.panel_fingerprint_failed_to_start));
        }
    }

    public e(k kVar) {
        d.h.b.c.c(kVar, "mPV");
        this.j = kVar;
        View findViewById = this.j.findViewById(R.id.fingerprintPanel);
        d.h.b.c.b(findViewById, "mPV.findViewById(R.id.fingerprintPanel)");
        this.f1611b = (ViewGroup) findViewById;
        this.f = new d(this);
        this.g = new a(this);
        this.h = c.f1616b;
        this.i = new b(this);
    }

    public void a() {
        m();
    }

    public boolean b(MotionEvent motionEvent) {
        d.h.b.c.c(motionEvent, "event");
        return l.a.a(this, motionEvent);
    }

    public void c() {
        l.a.d(this);
    }

    public void d() {
        this.f1612c = false;
        this.f1613d = 0;
    }

    public final void m() {
        this.e.removeCallbacksAndMessages((Object) null);
        this.f1611b.setVisibility(8);
        this.f1612c = false;
        this.h.run();
    }

    public final boolean n() {
        if (this.f1613d >= 2) {
            return false;
        }
        if (this.f1612c) {
            return true;
        }
        this.f1612c = true;
        View findViewById = this.f1611b.findViewById(R.id.fingerprint_title);
        if (findViewById != null) {
            ((TextView) findViewById).setText(R.string.pref_require_fingerprint_title);
            View findViewById2 = this.f1611b.findViewById(R.id.fingerprint_icon);
            if (findViewById2 != null) {
                ((ImageView) findViewById2).setImageResource(R.drawable.fingerprint_40px);
                View findViewById3 = this.f1611b.findViewById(R.id.fingerprint_status);
                if (findViewById3 != null) {
                    ((TextView) findViewById3).setText(R.string.panel_fingerprint_starting);
                    AlphaAnimation alphaAnimation = new AlphaAnimation(0.0f, 1.0f);
                    alphaAnimation.setDuration(250);
                    this.f1611b.startAnimation(alphaAnimation);
                    this.f1611b.setVisibility(0);
                    FingerprintActivity.e(this.i);
                    this.e.postDelayed(this.f, 5000);
                    return true;
                }
                throw new d.e("null cannot be cast to non-null type android.widget.TextView");
            }
            throw new d.e("null cannot be cast to non-null type android.widget.ImageView");
        }
        throw new d.e("null cannot be cast to non-null type android.widget.TextView");
    }
}
